home *** CD-ROM | disk | FTP | other *** search
/ Amiga News 95 / Amiga News 95.iso / dpat / dpat31 / iobject / sources.lha / sources / Generic.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-23  |  3.9 KB  |  236 lines

  1. // Methodes generiques pour les objets V0.27
  2. // (C) 1992 Christophe PASSUELLO
  3. // Thu Jan 21 12:03:55 1993
  4.  
  5. #include <mytypes.h>
  6. #define  INTUITION_PREFERENCES_H 0
  7. #include <intuition/intuition.h>
  8. #include "IObject_priv.h"
  9.  
  10. IMPORT UBYTE Pen1, Pen2;
  11.  
  12. PRIVATE struct Object *ActiveObject=NULL;
  13. PRIVATE ULONG ActiveFlags=NULL;
  14.  
  15.  
  16. //
  17. // Fonction que ne fait rien
  18. //
  19. VOID DoNothing()
  20. {
  21. }
  22.  
  23.  
  24. //
  25. // Renvoie le ObjectID
  26. //
  27. UWORD GetObjectID(struct Object *obj)
  28. {
  29.     return (obj->ObjectID);
  30. }
  31.  
  32.  
  33. //
  34. // Recupere le HotKey d'un Object
  35. //
  36. UBYTE GetHotKey(struct Object *obj)
  37. {
  38.     STRPTR label;
  39.  
  40.     if (obj->Flags & OBJ_DISABLED)
  41.         return (0);
  42.  
  43.     if (obj->Flags & LABEL_HOT_KEY)
  44.     {
  45.         label = strchr(obj->LabelText, '_');
  46.         return (label[1]);
  47.     }
  48.     else
  49.         return (0);
  50. }
  51.  
  52.  
  53. //
  54. // Libere un Objet
  55. //
  56. VOID DisposeObject(struct Object *obj)
  57. {
  58.     CloseFont(obj->Font);
  59.     FreeMem(obj, (LONG) obj->TMV->Size);
  60. }
  61.  
  62.  
  63. //
  64. // Ajoute un objet a une fenetre
  65. //
  66. VOID AddObject(struct ObjectGad *obj, struct Window *w, struct Requester *r)
  67. {
  68.     if (!obj->window)
  69.     {
  70.         AddGadget(w, &obj->Gadget, -1);
  71.         obj->window = w;
  72.     }
  73. }
  74.  
  75.  
  76. //
  77. // Retirer un objet de la fenetre
  78. //
  79. VOID RemoveObject(struct ObjectGad *obj)
  80. {
  81.     if (obj->window)
  82.     {
  83.         RemoveGList(obj->window, &obj->Gadget, 1);
  84.         obj->window = NULL;
  85.     }
  86. }
  87.  
  88.  
  89. //
  90. // Ghoste un ObjectGad
  91. //
  92. VOID OffObjectGad(struct ObjectGad *obj)
  93. {
  94.     OffGadget(&obj->Gadget, obj->window, obj->requester);
  95.     obj->Flags |= OBJ_DISABLED;
  96. }
  97.  
  98.  
  99. //
  100. // Initialise les champs communs aux objets
  101. //
  102. VOID InitObject(struct Object *obj, struct NewObject *newobj)
  103. {
  104.     obj->Flags = newobj->Flags;
  105.     obj->LabelText = newobj->LabelText;
  106.     obj->Font = LoadFont(newobj->Font);
  107.     obj->ClassFlags = newobj->ClassFlags;
  108.     COPY_BOX(&obj->BorderBox, &newobj->LeftEdge);
  109. }
  110.  
  111. //
  112. // Initailise les champs des objectgad
  113. //
  114. VOID InitObjectGad(struct ObjectGad *obj, struct NewObject *newobj)
  115. {
  116.     InitObject( (struct Object *)obj, newobj);
  117.     COPY_BOX(&obj->Gadget.LeftEdge, &newobj->LeftEdge);
  118.     obj->Gadget.GadgetID = OBJECTID;
  119.     obj->Gadget.UserData = obj;
  120. }
  121.  
  122.  
  123. //
  124. // Ajuste une boite suivant la type de bordure (simple on double)
  125. //
  126. VOID AdjustBox(struct Box *inner, BOOL single)
  127. {
  128.     if (single)
  129.     {
  130.         // BOX_1
  131.         inner->x += 2;        inner->y += 1;
  132.         inner->w -= 4;        inner->h -= 2;
  133.     }
  134.     else
  135.     {
  136.         // BOX_2
  137.         inner->x += 4;        inner->y += 2;
  138.         inner->w -= 8;        inner->h -= 4;
  139.     }
  140. }
  141.  
  142.  
  143. //
  144. // Efface le dessin d'un objet
  145. //
  146. VOID EraseObjectFrame(struct Object *obj, struct Box *box)
  147. {
  148.     struct TextEnv env;
  149.     struct RastPort *rp;
  150.  
  151.     // verifie que l'Object est dans une fenetre
  152.     if (obj->window)
  153.     {
  154.         rp = obj->window->RPort;
  155.         SaveTextEnv(rp, &env);
  156.  
  157.         FastEraseBox(box, rp);
  158.         EraseObjectLabel(obj, box);
  159.  
  160.         RestoreTextEnv(rp, &env);
  161.     }
  162. }
  163.  
  164.  
  165. //
  166. // Affiche le Label d'un objet par rapport a une boite
  167. //
  168. VOID PrintObjectLabel(struct Object *obj, struct Box *box)
  169. {
  170.     struct RastPort *rp;
  171.  
  172.     if (obj->LabelText)
  173.     {
  174.         UBYTE coul;
  175.  
  176.         rp = obj->window->RPort;
  177.         SetFont(rp, obj->Font);
  178.  
  179.         coul = (obj->Flags & LABEL_PEN2) ? Pen2 : Pen1;
  180.         SetAPen(rp, coul);
  181.         PrintLabelText(rp, box, obj->LabelText, obj->Flags & LABEL_MASK);
  182.     }
  183. }
  184.  
  185.  
  186. //
  187. // Efface le Label d'un objet par rapport a une boite
  188. //
  189. VOID EraseObjectLabel(struct Object *obj, struct Box *box)
  190. {
  191.     struct RastPort *rp;
  192.  
  193.     if (obj->LabelText)
  194.     {
  195.         rp = obj->window->RPort;
  196.         SetFont(rp, obj->Font);
  197.         EraseLabelText(rp, box, obj->LabelText, obj->Flags & LABEL_MASK);
  198.     }
  199. }
  200.  
  201.  
  202. //
  203. // Initialise l'objet Actif pour FindObjectMsg
  204. //
  205. VOID SetActiveObject(struct Object *obj, ULONG Flags)
  206. {
  207.     ActiveObject = obj;
  208.     ActiveFlags = Flags;
  209. }
  210.  
  211.  
  212. //
  213. // Cherche l'objet associe a l'IntuiMessage
  214. // Renvoie NULL si pas d'objet associe
  215. //
  216. struct Object *FindObjectMsg(struct IntuiMessage *msg)
  217. {
  218.     struct Gadget *gad;
  219.  
  220.     // si un objet est deja actif
  221.     if (ActiveObject && (msg->Class & ActiveFlags))
  222.         return (ActiveObject);
  223.     else
  224.     {
  225.         // pas d'objet actif
  226.         if (msg->Class & (GADGETUP|GADGETDOWN))
  227.         {
  228.             // c'est un gadget
  229.             gad = msg->IAddress;
  230.             if (gad->GadgetID == OBJECTID)
  231.                 return (gad->UserData);
  232.         }
  233.     }
  234.     return (NULL);
  235. }
  236.